package com.pospi.pospihold.util;

import com.lany.sp.SPHelper;

/**
 * Created by acer on 2018/10/11.
 */

public class OrderNoUtil {
    public static final String ORFER_NO = "ORFER_NO";
    public static final String ORFER_TIME = "ORFER_TIME";
    public static String getNumber(){
        String no = SPHelper.getInstance().getString(ORFER_NO, "");
        String time = SPHelper.getInstance().getString(ORFER_TIME, "");
        if (no.isEmpty() || !GetData.getYYMMDDTime().equals(time)) {
            no = "S" + GetData.getYYMMDDNoSpellingTime() + "0001";
        }
        SPHelper.getInstance().putString(ORFER_NO, no);
        SPHelper.getInstance().putString(ORFER_TIME,GetData.getYYMMDDTime());
        return no;
    }

    public static void updateNumber(){
        String no = SPHelper.getInstance().getString(ORFER_NO, "");
        String time = SPHelper.getInstance().getString(ORFER_TIME, "");
        if (no.isEmpty() || !GetData.getYYMMDDTime().equals(time)) {
            no = "S" + GetData.getYYMMDDNoSpellingTime() + "0000";
        }
        int number = Integer.parseInt(no.substring(no.length() - 4, no.length())) + 1;
        no = "S" + GetData.getYYMMDDNoSpellingTime()+String.format("%04d", number);
        SPHelper.getInstance().putString(ORFER_NO, no);
        SPHelper.getInstance().putString(ORFER_TIME,GetData.getYYMMDDTime());
    }
}
